/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */

package org.ipig.commons.helper;

import java.util.Properties;

/**
 * PropertiesHelper
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: PropertiesHelper.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public final class PropertiesHelper {
    private Properties properties;

    public PropertiesHelper(Properties properties) {
        this.properties = properties;
    }

    public String get(String key) {
        return this.properties.getProperty(key);
    }

    public String get(String key, String defaultVal) {
        String val = this.get(key);
        return val == null ? defaultVal : val;
    }

    public String findValue(String... keys) {
        String[] var2 = keys;
        int var3 = keys.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            String key = var2[var4];
            String value = this.get(key);
            if (value != null) {
                return value;
            }
        }

        return null;
    }

    public boolean getBoolean(String key, boolean defaultVal) {
        String val = this.get(key);
        return val == null ? defaultVal : Boolean.parseBoolean(val);
    }

    public long getLong(String key, long defaultVal) {
        String val = this.get(key);
        return val == null ? defaultVal : Long.parseLong(val);
    }

    public int getInt(String key, int defaultVal) {
        return (int)this.getLong(key, (long)defaultVal);
    }

    public double getDouble(String key, double defaultVal) {
        String val = this.get(key);
        return val == null ? defaultVal : Double.parseDouble(val);
    }

    public <T extends Enum<T>> T getEnum(String key, Class<T> type, T defaultValue) {
        String val = this.get(key);
        return val == null ? defaultValue : Enum.valueOf(type, val);
    }
}
